//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved

#pragma once

// Face:
// This class is a specialization of GameObject that represents a parallelogram primitive.
// The face is defined by three points.  It is positioned at 'origin'.  The four corners
// of the face are defined at 'origin', 'p1', 'p2' and 'p1' + ('p2' - 'origin').

#include "GameObject.h"

ref class Face: public GameObject
{
internal:
	Face();
	Face(
		DirectX::XMFLOAT3 origin,
		DirectX::XMFLOAT3 p1,
		DirectX::XMFLOAT3 p2
		);

	void SetPlane(
		DirectX::XMFLOAT3 origin,
		DirectX::XMFLOAT3 p1,
		DirectX::XMFLOAT3 p2
		);

	virtual void Update(GameEngine^ engine) override;

	virtual bool IsTouching(
		DirectX::XMFLOAT3 point,
		float radius,
		_Out_ DirectX::XMFLOAT3 *contact,
		_Out_ DirectX::XMFLOAT3 *normal
		);

	XMVECTOR VectorNormal();

private:
	void UpdateMatrix();

	DirectX::XMFLOAT3   m_widthVector;
	DirectX::XMFLOAT3   m_heightVector;
	DirectX::XMFLOAT3   m_normal;
	DirectX::XMFLOAT3   m_point[4];
	float               m_width;
	float               m_height;
	DirectX::XMFLOAT4X4 m_rotationMatrix;
};

__forceinline XMVECTOR Face::VectorNormal()
{
	return DirectX::XMLoadFloat3(&m_normal);
}
